package models.common.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Transient;

import models.common.entity.t_supervisor_audit.AuditResult;
import play.db.jpa.Model;

import common.constants.ConfConst;
import common.constants.Constants;
import common.utils.CropImage;
import common.utils.DateUtil;
import common.utils.Security;

/**
 * 信用额度申请表
 * 
 * @description
 * 
 * @author zhiliang.lan
 * @createDate 2017年4月14日
 */

@Entity
public class t_credit_limit extends Model {

	/**
	 * 构造器
	 */
	public t_credit_limit() {

	}

	/** 申请时间 */
	public Date time;

	/** 申请金额 */
	public double request_limit;

	/** 申请说明 */
	public String remark;

	/** 放款人id */
	public long supervisor_id;

	/** 放款人全称 */
	public String supervisor_name;

	/** 实际担保金额 */
	public double audit_amount;

	/** 审核结果 0 未审核 1 审核未通过 2 审核通过 */
	public int audit_status;

	/** 申请用户id */
	public long user_id;

	/** 审核时间 */
	public Date audit_time;

	/** 资料地址 */
	public String file_url;

	/** 授信编号 */
	public String credit_granting_code;

	/** 授信起始日期 */
	public Date start_time;

	/** 授信截止时间 */
	public Date end_time;
	
	/** 申请的授信期限 */
	public int duration;
	
	/** 加密ID */
	@Transient
	public String sign;

	public String getSign() {
		return Security.addSign(this.user_id, Constants.BID_ID_SIGN,
				ConfConst.ENCRYPTION_KEY_DES);
	}
	
	@Transient
	public String signId;
	
	public String getSignId() {
		return Security.addSign(this.id, Constants.BID_ID_SIGN,
				ConfConst.ENCRYPTION_KEY_DES);
	}
	
	@Transient
	public String supervisorSignId;
	
	public String getSupervisorSignId() {
		return Security.addSign(this.supervisor_id, Constants.BID_ID_SIGN,
				ConfConst.ENCRYPTION_KEY_DES);
	}

	/*public Date getEnd_time() {
		if (getAudit_status().code == AuditResult.AUDIT_PASS.code) {
			return DateUtil.addYear(audit_time, 1);
		}
		return null;
	}*/

	/** 审核结果 0 未审核 1 审核未通过 2 审核通过 */
	public AuditResult getAudit_status() {
		AuditResult auditResult = AuditResult.getEnum(this.audit_status);
		return auditResult;
	}

	public void setAudit_status(AuditResult auditResult) {
		this.audit_status = auditResult.code;
	}

	@Transient
	public List filelist;
	@Transient
	public List imglist;

	public List getImglist() {
		List picList = new ArrayList();
		if (file_url != null || !"".equals(file_url)) {
			try {
				picList = CropImage.getImgUrl(file_url);

			} catch (Exception e) {

			}
		}
		return picList;
	}

	public List getFilelist() {
		List picList = new ArrayList();
		if (file_url != null || !"".equals(file_url)) {
			try {
				picList = CropImage.getFileUrl(file_url);

			} catch (Exception e) {

			}
		}
		return picList;
	}
	
	
	/**
	 * @param financial_data
	 * @param income_tax
	 * @param bank_statement
	 * @param utility_bill
	 * @param pay_sheet
	 * @param purchase_sale_contracts
	 * @param financing_credit_information
	 * @param other_information
	 */
	public t_credit_limit(String financial_data, String income_tax,
			String bank_statement, String utility_bill, String pay_sheet,
			String purchase_sale_contracts,
			String financing_credit_information, String other_information) {
		super();
		this.financial_data = financial_data;
		this.income_tax = income_tax;
		this.bank_statement = bank_statement;
		this.utility_bill = utility_bill;
		this.pay_sheet = pay_sheet;
		this.purchase_sale_contracts = purchase_sale_contracts;
		this.financing_credit_information = financing_credit_information;
		this.other_information = other_information;
	}

	/**财务资料*/
	public String financial_data;
	/**所得税清缴报表*/
	public String income_tax;
	/**银行对账单*/
	public String bank_statement;
	/**水电费账单*/
	public String utility_bill;
	/**工资表和社保表单*/
	public String pay_sheet;
	/**购销合同*/
	public String purchase_sale_contracts;
	/**融通增信资料*/
	public String financing_credit_information;
	/**其他资料*/
	public String other_information;
}